<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8" />
    <title>split()函数</title>
</head>
<body>
    <script>
        //split()函数:按照规定规则分割字符串，返回一个由分割出来的字符串组成的数组
        var str1 = "hel|lo| wo|rld!";
        document.write(str1.split('|'),"<br>");//hel,lo, wo,rld!

        //如果分割规则为空字符串，则返回数组的成员时原字符串的每一个字符
        var str2 = "a|b|c";
        document.write(str2.split(""),"<br>");//a,|,b,|,c

        //如果省略参数，则返回原字符串
        var str3 = "a|b|c";
        document.write(str3.split(),"<br>");//a|b|c

        //函数还可以接收第二个参数，限定返回数组的最大成员数
        var str4 = "a|b|c";
        document.write(str4.split("",0),"<br>");//""
        document.write(str4.split("",1),"<br>");//a
        document.write(str4.split("",5),"<br>");//a,|,b,|,c
        document.write(str4.split("",6),"<br>");//a,|,b,|,c
        
    </script>
</body>
</html>